package com.cqupt.qualityevaluation.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.cqupt.qualityevaluation.dao.EvaluateIndex1Mapper;
import com.cqupt.qualityevaluation.dao.EvaluateIndex3Mapper;
import com.cqupt.qualityevaluation.pojo.evaluateindex1;
import com.cqupt.qualityevaluation.pojo.evaluateindex2;
import com.cqupt.qualityevaluation.pojo.evaluateindex3;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/evaluateindex3")
public class EvaluateIndex3Controller {
    @Autowired
    private EvaluateIndex3Mapper evaluateIndex3Mapper;
    @GetMapping("/findAll")
    public List<evaluateindex3> findAll(){
        return evaluateIndex3Mapper.selectList(null);
    }
    @PostMapping("/save")
    //通过RequestBody主要用来接收前端传递给后端的json字符串中的数据的(请求体中的数据的),将JSON对象转换为java对象
    public Object save(@RequestBody evaluateindex3 s){
        Map map=new HashMap<>();
        int result=0;
        try {
            result=evaluateIndex3Mapper.insert(s);
        }catch (Exception e){
            map.put("code","fail");
            map.put("msg","该评价号已存在");
            return map;
        }
        if (result==1){
            map.put("code","success");
            map.put("msg","添加成功");
        }
        else {
            map.put("code", "fail");
            map.put("msg","添加失败");
        }
        return map;
    }
    @DeleteMapping("/delete/{id}")
    public String delete(@PathVariable("id") String id){
//        QueryWrapper<evaluateindex1> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("id",id);
        evaluateIndex3Mapper.deleteById(id);
        return "success";
    }
    @PutMapping("/update")
    public Object update(@RequestBody evaluateindex3 s){
        Map map=new HashMap<>();
        int result=0;
        UpdateWrapper<evaluateindex3> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",s.getId());
        evaluateindex3 evaluateindex3=new evaluateindex3();
        evaluateindex3.setEvaluateindex3id(s.getEvaluateindex3id());
        evaluateindex3.setEvaluateindex3name(s.getEvaluateindex3name());
        evaluateindex3.setEvaluateindex2id(s.getEvaluateindex2id());
        evaluateindex3.setEvaluatevaluetype(s.getEvaluatevaluetype());
        evaluateindex3.setEvaluatevaluelengthlimit(s.getEvaluatevaluelengthlimit());
        evaluateindex3.setEvaluatevalueselected(s.getEvaluatevalueselected());
        evaluateindex3.setEvaluatememo(s.getEvaluatememo());
        try{
            result=evaluateIndex3Mapper.update(evaluateindex3,updateWrapper);
        }catch (Exception e){
            map.put("code","fail");
            map.put("msg","该评价号已存在");
            return map;
        }
        if (result==1){
            map.put("code","success");
            map.put("msg","更新成功");
        }
        else {
            map.put("code", "fail");
            map.put("msg","添加失败");
        }
        return map;
    }
    @GetMapping("/selectone/{id}")
    public evaluateindex3 findByevaluateindexId(@PathVariable("id") String id){
        QueryWrapper<evaluateindex3> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);
        return evaluateIndex3Mapper.selectOne(queryWrapper);
    }
    @GetMapping("/search/9/{evaluateindex3id}")
    public List<evaluateindex3> findByevaluateIndex3ID(@PathVariable("evaluateindex3id") String evaluateindex3id){
        QueryWrapper<evaluateindex3> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("evaluateindex3id",evaluateindex3id);
        return evaluateIndex3Mapper.selectList(queryWrapper);
    }
    @GetMapping("/search/10/{evaluateindex3name}")
    public List<evaluateindex3> findByevaluateIndex3Name(@PathVariable("evaluateindex3name") String evaluateindex3name){
        QueryWrapper<evaluateindex3> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("evaluateindex2name",evaluateindex3name);
        return evaluateIndex3Mapper.selectList(queryWrapper);
    }
    @GetMapping("/search/11/{evaluateindex2id}")
    public List<evaluateindex3> findByevaluateID(@PathVariable("evaluateindex2id") String evaluateindex2id){
        QueryWrapper<evaluateindex3> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("evaluateindex2id",evaluateindex2id);
        return evaluateIndex3Mapper.selectList(queryWrapper);
    }
    @GetMapping("/search/12/{evaluatevaluetype}")
    public List<evaluateindex3> findByevaluateValueType(@PathVariable("evaluatevaluetype") String evaluatevaluetype){
        QueryWrapper<evaluateindex3> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("evaluatevaluetype",evaluatevaluetype);
        return evaluateIndex3Mapper.selectList(queryWrapper);
    }
    @GetMapping("/search/13/{evaluatevaluelengthlimit}")
    public List<evaluateindex3> findByevaluateIndex1Content(@PathVariable("evaluatevaluelengthlimit") String evaluatevaluelengthlimit){
        QueryWrapper<evaluateindex3> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("evaluatevaluelengthlimit",evaluatevaluelengthlimit);
        return evaluateIndex3Mapper.selectList(queryWrapper);
    }
    @GetMapping("/search/14/{evaluatevalueselected}")
    public List<evaluateindex3> findByevaluateValueSelected(@PathVariable("evaluatevalueselected") String evaluatevalueselected){
        QueryWrapper<evaluateindex3> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("evaluatevalueselected",evaluatevalueselected);
        return evaluateIndex3Mapper.selectList(queryWrapper);
    }
    @GetMapping("/search/15/{evaluatememo}")
    public List<evaluateindex3> findByevaluateMemo(@PathVariable("evaluatememo") String evaluatememo){
        QueryWrapper<evaluateindex3> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("evaluatememo",evaluatememo);
        return evaluateIndex3Mapper.selectList(queryWrapper);
    }
}